package main

func main() {
	println(longestSubsequence([]int{1, 5, 7, 8, 5, 3, 4, 2, 1}, -2))
}

/**
 *	longestSubsequence
 *	@Description: 动态规划
 *	@param arr []int
 *	@param difference int
 *	@return res int
 */
func longestSubsequence(arr []int, difference int) (res int) {
	m := make(map[int]int)
	for _, v := range arr {
		m[v] = m[v-difference] + 1
		if m[v] > res {
			res = m[v]
		}
	}
	return
}
